package com.yohann.designPattern.factory.abstractFactory.comsume;

import com.yohann.designPattern.factory.abstractFactory.factory.AbstractFactory;
import com.yohann.designPattern.factory.simpleFactory.pizza.Pizza;

import java.util.Scanner;

/**
 * <p>
 * 消费披萨🍕
 * </p>
 *
 * @author Yohann
 * @since 2021/2/1 21:16
 */
public class OrderPizza {
    private final Scanner scanner = new Scanner(System.in);
    private AbstractFactory factory;

    public OrderPizza(AbstractFactory factory) {
        setFactory(factory);
    }

    private void setFactory(AbstractFactory factory) {
        do {
            String type = scanner.nextLine();
            Pizza pizza = factory.create(type);

            if (pizza != null) {
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }
        } while (true);
    }
}